import java.io.IOException;
import java.net.*;

public class UdpClient {
    private final static int PORT = 5683;
    private static final String HOST_NAME = "180.101.147.115";


    public static void main(String[] args) {
        try {
            DatagramSocket socket = new DatagramSocket(0);
            socket.setSoTimeout(10000);
            InetAddress host = InetAddress.getByName(HOST_NAME);
            String data = "hello world";
            System.out.println("Send to server: " + data);
            byte[] sendData = data.getBytes();
            DatagramPacket request = new DatagramPacket(sendData, sendData.length, host, PORT);
            DatagramPacket response = new DatagramPacket(new byte[1024], 1024);

            socket.send(request);
            socket.receive(response);
            String result = new String(response.getData(), 0, response.getLength());
            System.out.println("From IP: " + response.getAddress() + " receive: " + result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
